package com.lzh.gulimall.order.web;

import com.lzh.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @ClassName HelloController
 * @Description TODO
 * @Author liuzhihui
 * @Date 2020/9/3 22:54
 * @Version 1.0
 **/
@Controller
public class HelloController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发消息，测试
     * @return
     */
    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrderTest(){
        //订单下单成功
        OrderEntity orderEntity=new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        orderEntity.setModifyTime(new Date());
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "ok";
    }


    @GetMapping("/{page}.html")
    public String listPage(@PathVariable("page")String page){

        return page;
    }

}
